package com.ruoyi.app.controller.message;

import com.ruoyi.app.business.message.MessageBusiness;
import com.ruoyi.app.domain.message.MessageDetail;
import com.ruoyi.app.domain.message.MessageSimple;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.message.query.MessageBaseQuery;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息控制器
 *
 * @author Zane
 * @since 2025-10-25 1:21
 */
@RestController
@RequestMapping("/message/")
public class MessageController {

  @Resource
  private MessageBusiness messageBusiness;
  /**
   * 未读消息数量
   */
  @RequestMapping("unreadCount")
  public APIResult<Long> messageList() {
    final Long unreadCount = messageBusiness.unreadCount();
    return APIResult.success(unreadCount);
  }

  /**
   * 我的消息列表
   */
  @RequestMapping("list")
  public TableDataInfo<MessageSimple> messageList(@Validated @RequestBody MessageBaseQuery query) {
    CommonPageInfo<MessageSimple> messageList = messageBusiness.messageList(query);
    return CommonUtils.buildTableData(messageList);
  }

  /**
   * 消息明细
   */
  @GetMapping("detail")
  public APIResult<MessageDetail> messageDetail(@RequestParam("messageId") Long messageId) {
    MessageDetail detail = messageBusiness.messageDetail(messageId);
    return APIResult.success(detail);
  }

  /**
   * 标记查看
   */
  @RequestMapping("check")
  public APIResult<Void> messageCheck(@RequestParam("messageId") Long messageId) {
    messageBusiness.messageCheck(messageId);
    return APIResult.success();
  }
}
